<script type="text/javascript" src="{:U(MODULE_NAME. '/Public/editor')}"></script>
<script language="javascript" type="text/javascript" src="__PUBLIC__/plugin/autocomplete/jquery.autocomplete.js"></script>
<script type="text/javascript" src="/Public/js/jquery.form.min.js"></script>
<link rel="stylesheet" href="__PUBLIC__/plugin/autocomplete/jquery.autocomplete.css">

<div class="main_top">
<a href="{:U(MODULE_NAME.'/Product/edit', array('id'=>$vo['id']))}" class=" <if condition='$step eq 0'>bg_blue</if>">主要信息</a>
<a href="{:U(MODULE_NAME.'/Product/edit', array('id'=>$vo['id'],'step'=>1))}" class=" <if condition='$step eq 1'>bg_blue</if>">产品亮点</a> 
<a href="{:U(MODULE_NAME.'/Trip/index', array('id'=>$vo['id']))}" class="<if condition='$a eq "/Trip/index"'>bg_blue</if>">行程参考</a>
<a href="{:U(MODULE_NAME.'/Product/edit', array('id'=>$vo['id'],'step'=>5))}" class=" <if condition='$step eq 5'>bg_blue</if>">费用包括</a> 
<a href="{:U(MODULE_NAME.'/Product/edit', array('id'=>$vo['id'],'step'=>6))}" class=" <if condition='$step eq 6'>bg_blue</if>">预定须知</a> 
<a href="{:U(MODULE_NAME.'/Product/edit', array('id'=>$vo['id'],'step'=>7))}" class=" <if condition='$step eq 7'>bg_blue</if>">温馨提示</a> 
<a href="{:U(MODULE_NAME.'/Product/edit', array('id'=>$vo['id'],'step'=>8))}" class=" <if condition='$step eq 8'>bg_blue</if>">赠送信息</a> 
<a href="{:U(MODULE_NAME.'/Product/edit', array('id'=>$vo['id'],'step'=>9))}" class=" <if condition='$step eq 9'>bg_blue</if>">附加保险</a> 
<a href="{:U(MODULE_NAME.'/Product/edit', array('id'=>$vo['id'],'step'=>10))}" class=" <if condition='$step eq 10'>bg_blue</if>">优惠券</a> 
<a href="{:U(MODULE_NAME.'/Product/edit', array('id'=>$vo['id'],'step'=>11))}" class=" <if condition='$step eq 11'>bg_blue</if>">附加产品</a> 
<a href="{:U(MODULE_NAME.'/Departure/index',array('pid'=>$vo['id']))}">出发日期</a>
<a href="{:U(MODULE_NAME.'/AirplaneManage/index',array('pid'=>$vo['id']))}">航班信息</a>
<a href="{:U(MODULE_NAME.'/HotelManage/index',array('pid'=>$vo['id']))}" >酒店信息</a>
</div>
  <div class="form">
    <form method='post' id="form_do" name="form_do" action="{:U('/Home/Product/edit')}">
    <if condition="$step eq NULL">
      <input type="hidden" id="departure_province" value="{$departure_province}" />
      <input type="hidden" id="destination_continent" value="{$destination_continent}" />
              <dl>
                <dt> 所属类型：</dt>
                <dd>
                    <foreach name="cate_name" item="cate_name">
                    <input type="checkbox" name="catid[]" value="{$cate_name.id}" style="margin-left:10px;" <if condition="$cate_name['checked'] eq true">checked</if> />{$cate_name.name}
                    </foreach>
                </dd>
              </dl>
              <dl>
                <dt>线路名称：</dt>
                <dd>
                  <input type="text" name="title" class="inp_one inp_w550" maxlength="30" value="{$vo.title}" /><font color="red">(最长30个字符)</font>
                  &nbsp;<input type="checkbox" name="verify" value="1" <if condition='$vo.verify eq 1'>checked</if> />&nbsp;二次确认 </dd>
              </dl>
              <dl>
                <dt>扩展名称：</dt>
                <dd>
                  <input type="text" name="extend" class="inp_one inp_w550" maxlength="35" value="{$vo.extend}" /> <font color="red">(最长35个字符)</font>
                </dd>
              </dl>
              <dl>
                 <dt>供应商：</dt>
                 <dd>
                <input type="text" name="supplier" id="supplier" value="{$vo.suppliername}"><font color="#FF0000">*</font>
                 </dd>
              </dl>
              <dl style="margin-bottom: 0px;">
                <dt> 出发地：</dt>
                <dd>
                <div>
                  <span id="departure_add" >
                  {$departure}
                  </span>
                  <div><input type="checkbox" <if condition="$vo['localid'] neq ''">checked</if> id="check"/>当地游</div>
                  <div><input type="checkbox" <if condition="$vo['visa'] eq 1">checked</if> name="visa" value="" id="visa" onchange="visaValue(this)"/>签证类</div>
                </div>
                </dd>
              </dl>
              <dl <if condition="$vo['localid'] neq ''">style="display:block;"<else />style="display:none;"</if>  id="local" >
                <dt></dt>
                <dd>
                  <foreach name="localplay_name" item="localplay_name" key="key">
                    <span style="margin-right:10px;" ><input type="checkbox" name="localid[]" value="{$localplay_name.id}" <if condition="$localplay_name['checked'] eq true">checked</if> />{$localplay_name.name}</span>
                  </foreach>
                </dd>
              </dl>
              <dl>
            <dt></dt>
            <dd><div><span onclick="departure_add()" class="button-green">添加多出发地</span></div></dd>
          </dl>
              <dl>
                <dt>目的地：</dt>
                <dd>
                  <div id="destination_add">
                  {$destination}
                  </div>
                  <div><span onclick="destination_add()" class="button-green">添加多目的地</span></div>
                </dd>
              </dl>
              <dl>
                <dt> 出发时间：</dt>
                <dd>
                  <input type="text" class="inp_default" name="departure_time" id="departure_time" value="{$vo.departure_time}">
                </dd>
              </dl>
              <dl>
                <dt> 行程天数 ：</dt>
                <dd>
                  <input type="text" name="travel_days" class="inp_one inp_w30" value="{$vo.travel_days}" />
                  日
                  <input type="text" name="travel_night" class="inp_one inp_w30"  value="{$vo.travel_night}"/>
                  晚 </dd>
              </dl>
               <dl>
                <dt> 市场价：</dt>
                <dd>
                  <input type="text" name="market_price" class="inp_small" value="{$vo.market_price}"/> /人起
                </dd>
              </dl>
              <dl>
                <dt> 现价：</dt>
                <dd>
                  <input type="text" name="price" class="inp_small" value="{$vo.price}"/> /人起
                </dd>
              </dl>
               <dl>
                <dt> 产品缩略图：</dt>
                <dd>
					<div class="litpic_show">
					    <div style="float:left;">
					    <input type="text" class="inp_w250" name="litpic" readonly id="litpic"  value="{$vo.litpic}" />
					    </div>
							<div class="litpic_btn" id="litpic_btn">
					        <span>添加缩略图</span>
					        <input id="fileupload" type="file" name="mypic">
					    </div>
					    <font color="red">(尺寸:320px*210px)</font>
					    <div class="litpic_tip"></div>
					    <div id="litpic_show">
					    <if condition="$vo['litpic']"><img src="{$website_url}{$vo.litpic}" width='120' /></if>
					    </div>
					</div>
                </dd>
              </dl>
              
              <dl>
                <dt> 产品大图：</dt>
                <dd>
					<div class="bigpic_show">
					    <div style="float:left;">
					    <input type="text" class="inp_w250" readonly name="bigpic" id="bigpic"  value="{$vo.bigpic}" />
					    </div>
							<div class="litpic_btn" id="bigpic_btn">
					        <span>添加大图</span>
					        <input id="fileupload2" type="file" name="mypic2">
					    </div>
					    <font color="red">(尺寸:宽度1920px为佳，比例2:1)</font>
					    <div class="bigpic_tip"></div>
					    <div id="bigpic_show">
					    <if condition="$vo['bigpic']"><img src="{$website_url}{$vo.bigpic}" width='120' /></if>
					    </div>
					</div>
                </dd>
              </dl>
              <dl>
                <dt> 关键词：</dt>
                <dd>
                  <input type="text" name="keywords" class="inp_w250" value="{$vo.keywords}" />
                  <span class="tip">多关键词之间以英文逗号","分隔</span></dd>
              </dl>
              <elseif condition="$step eq 1" />
              <if condition="$points eq '' " >
              <dl>
                <dt> 亮点1： </dt>
                <dd>
                  <input type="text"  name="points[]" class="inp_large" value="" />
              </dl>
              <dl>
                <dt> 亮点2： </dt>
                <dd>
                  <input type="text"  name="points[]" class="inp_large" value="" />
              </dl>
              <dl>
                <dt> 亮点3： </dt>
                <dd>
                  <input type="text"  name="points[]" class="inp_large" value="" />
              </dl>
              <dl>
                <dt> 亮点4： </dt>
                <dd>
                  <input type="text"  name="points[]" class="inp_large" value="" />
              </dl>
              <else />
              <foreach name="points" key="key" item="p">
                <dl>
                  <dt> 亮点{$key+1}： </dt>
                  <dd>
                    <input type="text"  name="points[]" class="inp_large" value="{$p.content}" />
                    <input type="hidden"  name="points_id[]" class="inp_large" value="{$p.id}" />
                </dl>
              </foreach>
              </if>
              <elseif condition="$step eq 5" />

              <dl>
                <dt> 费用包含 ：</dt>
                <dd>
                  <textarea name="costcontent" id="content">{$detail.costInclude}</textarea>
                </dd>
              </dl>
              
               <elseif condition="$step eq 6" />
               
              <dl>
                <dt> 预定须知： </dt>
                <dd>
                  <textarea name="noticecontent" id="content">{$detail.reservationNotice}</textarea>
                </dd>
              </dl>
              <elseif condition="$step eq 7" />
              
              <dl>
                <dt> 温馨提示内容： </dt>
                <dd>
                  <textarea name="hintcontent" id="content">{$detail.warmReminder}</textarea>
                </dd>
              </dl>
              <elseif condition="$step eq 8" />
               <style>
				.picture_item {margin:5px;  padding: 5px 5px 40px ; cursor:pointer; height: 150px;}
				.picture_item2 {border: 1px solid #ff0000;}
				.picture_item .title {padding-left:6px;overflow:hidden;	width:120px;}
				.page { border-bottom: 0 solid #ccc;}
			 </style>
             <dl>
                <dt> 选择赠品：</dt>
                <dd>
                	 <div id="picture_show" style="width:1000px">
                      <foreach name='giftlist' item='gift'>
                        <div class="picture_item {$gift.picture_item2}">
                          <label for="gift{$gift.id}">
                          <div class="title">{$gift.title}</div>
                          <img width="120" height="120" src="{$website_url}{$gift.litpic}">
                          </label>
                          <input type="checkbox" id="gift{$gift.id}" name="gift[]" value="{$gift.id}" style="margin-left: 48px;" {$gift.checked}>
                        </div>
                      </foreach>
                      <div class="page" style="clear: both;">{$page}</div>
                    </div>
              	</dd>
             </dl>
             <elseif condition="$step eq 9" />
             <dl>
                <dt> 选择保险：</dt>
                <dd>
                  <style>
                .picture_item {margin:5px;  padding: 5px 5px 40px ; width: 120px; height:160px; cursor:pointer;}
				.picture_item2 {border: 1px solid #ff0000;}
                .picture_item .title {padding-left:6px;overflow:hidden;	width:120px; height:18px}
                .picture_item .description { height: 39px;  line-height: 18px; overflow: hidden; padding-left: 6px; width: 120px;}
                .page {border-bottom: 0px;}
                 </style>
                  <div id="picture_show" style="width:1000px">
                    <foreach name='insurancelist' item='v'>
                      <div class="picture_item {$v.picture_item2}" >
                        <label for="insurance{$v.id}">
                        <div class="title">{$v.title}</div>
                        <img width="120" height="120" src="<if condition='$v.litpic eq null'>__PUBLIC__/image/baoxian.jpg<else/>http://www.tripvip.cn{$v.litpic}</if>">
                        <div class="description">{$v.description}</div>
                        </label>
                        <input type="checkbox" id="insurance{$v.id}" name="insurance[]" value="{$v.id}" style="margin-left: 48px;" {$v.checked} />
                      </div>
                    </foreach>
                    <div class="page" style="clear: both;">{$page}</div>
                  </div>
                </dd>
              </dl>
              <dl style="display:none">
                <dt> 保险提示内容： </dt>
                <dd>
                  <textarea name="insurancecontent" id="content">{$vo.insurancecontent}</textarea>
                </dd>
              </dl>
              <elseif condition="$step eq 10" />
               <dl>
                <dt> 优惠券选择：</dt>
                <dd>
                  <style>
                .picture_item {margin:5px;  padding: 5px 5px 40px ; width: 120px; height:180px; cursor:pointer;}
				.picture_item2 {border: 1px solid #ff0000;}
                .picture_item .title {padding-left:6px;overflow:hidden;	width:120px;}
                .picture_item .description { height: 18px;  line-height: 18px; overflow: hidden; padding-left: 6px; width: 120px;}
				.picture_item .count { height: 34px;  line-height: 18px; overflow: hidden; padding-left: 6px; width: 120px;}
                .page {border-bottom: 0px;}
                 </style>
                  <div id="picture_show" style="width:1000px">
                    <foreach name='coupontypelist' item='v'>
                      <div class="picture_item {$v.picture_item2}" >
                        <label for="coupon{$v.id}">
                        <div class="title">{$v.name}</div>
                        <img width="120" height="120" src="<if condition='$v.litpic eq null'>__PUBLIC__/image/baoxian.jpg<else/>http://www.tripvip.cn{$v.litpic}</if>">
                        <div class="description">¥{$v.amount}</div>
                        </label>
                        <input type="checkbox" id="coupon{$v.id}" name="coupon[]" value="{$v.id}" style="margin-left: 48px;" {$v.checked} />
                      </div>
                    </foreach>
                  </div>
                </dd>
              </dl>
              <dl style="display:none">
                <dt> 兑换提示内容： </dt>
                <dd>
                  <textarea name="insurancecontent" id="content">{$vo.insurancecontent}</textarea>
                </dd>
              </dl>
              <elseif condition="$step eq 11" />
              <dl>
			 	<dt></dt>
			 	<dl><font color="red">临时附加产品用于补差价;</font></dl>
			 </dl>
			 <dl>
                <dt>临时附加产品：</dt>
                <dd>
                  <div id="addproduct_add">
                  	<foreach name="addproduct_list" item="addproduct_list" >
	                  	<div>
	                  		<input type="text" size="100" name="title[]" class="inp_w250" placeholder="名称" value="{$addproduct_list.title}">
	                  		-
	                  		<input type="text" size="100" name="price[]" class="inp_small" placeholder="价格" value="{$addproduct_list.price}">
	                  		<span onclick="addproduct_del(this)" class="span_del"><a href="javascript:" class="button-red" style="color:#fff; padding:2px 10px">删除</a></span>
	                  	</div>
                  	</foreach>
                  </div>
                  <div><span class="valAdd" onclick="addproduct_add()">添加临时附加产品</span></div>
                </dd>
              </dl>
			 <dl>
			 	<dt></dt>
			 	<dl><font color="red">附加产品库在产品页会有详细的描述;</font></dl>
			 </dl>
			   <style>
          .picture_item {margin:5px; width: 120px; height:auto; cursor:pointer;}
  				.picture_item2 {border: 1px solid #ff0000;}
          .picture_item .title {overflow:hidden;	width:120px;}
          .picture_item .description { height: 18px;  line-height: 18px; overflow: hidden; padding-left: 6px; width: 120px;}
  				.picture_item .count { height: 34px;  line-height: 18px; overflow: hidden; padding-left: 6px; width: 120px;}
          .page {border-bottom: 0px;}
          </style>
              <dl>
                <dt>附加产品库：</dt>
                <dd>
                  <div id="picture_show" style="width:1000px">
                    <foreach name='addproduct' item='addproduct'>
                      <div class="picture_item {$addproduct.picture_item2}" >
                        <label for="coupon{$addproduct.id}">
                        <div class="title">{$addproduct.title}</div>
                        </label>
                        <input type="checkbox" id="coupon{$addproduct.id}" name="addproduct[]" value="{$addproduct.id}" style="margin-left: 48px;margin-top: 10px;margin-bottom: 10px;" {$addproduct.checked} />
                      </div>
                    </foreach>
                  </div>
                </dd>
              </dl>
              </if>
        <div class="form_b" style="width: 300px; margin-left: 110px;">
        <input type="hidden" name="id" value="{$vo.id}" />
        <input type="hidden" name="pid" value="{$pid}" />
        <input type="hidden" name="step" value="{$step}" />
        <input type="submit" class="button-green" id="submit" value="保 存">
        &nbsp;<input type="button" onclick="goUrl('{:U('/Home/Product/index', array('pid'=>$pid))}')" class="button-return" value="返回产品列表">
      </div>
    </form>
  </div>
 <script type="text/javascript">

 /**
 * [visaValue description]
 * @param  {[type]} obj [description]
 * @return {[type]}     [description]
 */
function visaValue(obj)
{
  var checked = $(obj).attr('checked');
  if(checked == 'checked')
    {
      $(obj).val('1');
    }
    else
    {
      $(obj).val('');
    }
}

//autocomplete
function formatItem(row){return row;}
function findValue(li) { 
	if( li == null ) return false; 
	var sValue = li.selectValue; 
	if( !!li.extra )
	{
		sValue = li.extra[0];
	}
}
function selectItem(li) {findValue(li);} 

$(function() {
	
	$('#supplier').autocomplete("{:U('Home/Public/autoSupplierComplete')}",
	{
		delay:10, 
		minChars:1, 
		matchSubset:1, 
		matchContains:1, 
		cacheLength:10, 
		onItemSelect:selectItem, 
		onFindValue:findValue, 
		formatItem:formatItem, 
		autoFill:false 
	});

    var litpic_tip = $(".litpic_tip");
	var btn = $("#litpic_btn span");
	$("#fileupload").wrap("<form id='myupload' action='{:U(MODULE_NAME. '/Public/uploadPic',array('fileType' =>'Img','type'=>'Product'))}' method='post' enctype='multipart/form-data'></form>");
    $("#fileupload").change(function(){
    	if($("#fileupload").val() == "") return;
		$("#myupload").ajaxSubmit({
			dataType:  'json',
			beforeSend: function() {
        		$('#litpic_show').empty();
				btn.html("上传中...");
    		},
			success: function(data) {
				//litpic_tip.html("<b>"+data.title+"("+data.size+"k)</b> <span class='delimg' rel='"+data.url+"'>删除</span>");
				if(data.state == 'SUCCESS'){					
					litpic_tip.html(""+ data.title +" 上传成功("+data.size+"k)");
					var img = data.url;//原图
					var timg = data.turl;//缩略图
					$('#litpic_show').html("<img src='{$website_url}"+timg+"' width='120'>");
					$("#litpic").val(timg);
				}else {
					litpic_tip.html(data.state);		
				}			
				btn.html("更换图片");

			},
			error:function(xhr){
				btn.html("上传失败");
				litpic_tip.html(xhr);
			}
		});
	});
    
    var bigpic_tip = $(".bigpic_tip");
	var btn2 = $("#bigpic_btn span");
	$("#fileupload2").wrap("<form id='myupload2' action='{:U(MODULE_NAME. '/Public/uploadPic',array('fileType' =>'Img','type'=>'Product'))}' method='post' enctype='multipart/form-data'></form>");
    $("#fileupload2").change(function(){
    	if($("#fileupload2").val() == "") return;
		$("#myupload2").ajaxSubmit({
			dataType:  'json',
			beforeSend: function() {
        		$('#bigpic_show').empty();
        		btn2.html("上传中...");
    		},
			success: function(data) {
				if(data.state == 'SUCCESS'){					
					bigpic_tip.html(""+ data.title +" 上传成功("+data.size+"k)");
					var img = data.url;//原图
					var timg = data.turl;//缩略图
					$('#bigpic_show').html("<img src='{$website_url}"+timg+"' width='120'>");
					$("#bigpic").val(timg);
				}else {
					bigpic_tip.html(data.state);		
				}			
				btn2.html("更换图片");

			},
			error:function(xhr){
				btn2.html("上传失败");
				bigpic_tip.html(xhr);
			}
		});
	});
    
    $('#check').change(function(){
        var a = $('#check').attr('checked');
        if(a == 'checked'){
          $('#chinaprovince').val('');
          $('#chinaprovince').attr('disabled',true);
          $('#local').removeAttr('style');
        }else{
          $('#chinaprovince').removeAttr('disabled');
          $('#local').css('display','none');
          $("[name='localid[]']").removeAttr("checked");
        }
    });

    
});
function departure_add()
{
	var select = '<div><select name="province[]">';
	select += $("#departure_province").val();
	select += '</select>';
	select += '<span onclick="departure_del(this)" class="span_del"><a href="javascript:" class="button-red" style="color:#fff; padding:2px 10px">删除</a></span></div>';
	$('#departure_add').append(select);
}

function departure_del(o)
{
	i = $(o).parent().parent().find("div").length;
	if(i==1)
	{
		alert("最少保留一个选择项");
	}
	else
	{
		$(o).parent().remove();
	}
}

function destination(o,type)
{
  var div = $(o).parent();
  var get = {};
  var obj = $(o);
  
  if(type==1)
  {
	get.continent = div.find('[name="continent[]"]').val();
    obj = div.find('[name="country[]"]');
  }
  else if(type==2)
  {
    get.country = div.find('[name="country[]"]').val();
    obj = div.find('[name="city[]"]');
  }
  else
  {
	  return false;
  }

  $.get('/Home/Public/ajaxDestination',get, function (data, textStatus){
    obj.html(data);
  });
}

function destination_add()
{
    var select = '';
	select += '<div><select name="continent[]" onchange="destination(this,1)">';
    select += $("#destination_continent").val();
    select += '</select>';
    select += '<select name="country[]"  onchange="destination(this,2)">';
    select += '<option value="">请选择国家</option>';
    select += '</select>';
    select += '<select name="city[]" >';
    select += '<option value="">请选择城市</option>';
    select += '</select>';
    select += '<span onclick="destination_del(this)" class="span_del"><a href="javascript:" class="button-red" style="color:#fff; padding:2px 10px">删除</a></span></div>';
    $('#destination_add').append(select);
}

function destination_del(o)
{
	i = $(o).parent().parent().find("div").length;
	if(i==1)
	{
		alert("最少保留一个选择项");
	}
	else
	{
		$(o).parent().remove();
	}
}
function addproduct_add()
{
	var content = '<div>';
	content += '<input type="text" size="100" name="title[]" class="inp_w250" placeholder="名称" value="">';
	content += ' - <input type="text" size="100" name="price[]" class="inp_small" placeholder="价格" value="">';
	content += '<span onclick="addproduct_del(this)" class="span_del"><a href="javascript:" class="button-red" style="color:#fff; padding:2px 10px">删除</a></span></div>';
	$('#addproduct_add').append(content);
}

function addproduct_del(o)
{
	$(o).parent().remove();
}

</script>